const {ccclass, property} = cc._decorator;

@ccclass
export default class BulletManager{

    bulletArr:cc.Node[] = []
    private static _instance: BulletManager = null;
    //构造函数私有化
    private constructor(){}
    //获取单例
    public static getInstance(): BulletManager {
        if (BulletManager._instance == null){
            BulletManager._instance = new BulletManager();
        } 
        return BulletManager._instance;
    }
    
    //添加子弹
    public addBullet(bullet:cc.Node){
        this.bulletArr.push(bullet)
        console.log("数量：" + this.bulletArr.length)
    }

    //回收子弹
    public collection(bullet:cc.Node){
        //查找bullet在数组的下标
        const index = this.bulletArr.indexOf(bullet)
        //删除从下标开始的1个元素
        this.bulletArr.splice(index, 1)
        bullet.destroy()
    }

    //销毁同一目标的子弹

}
